(function (window) {
    function isFooterPosition() {
        let winHt = $(window).height();
        let conHt = $('body').height();
        if (conHt < winHt) {
            $('footer').css({ 'position': 'fixed', 'bottom': '0px', 'left': '0px' })
        }
        else{
            $('footer').css({ 'position': 'inherit'})
        }
    }
    function createScrollDom(container, area, altitude) { //参数：容器id/ 显示区域id/实际高度id  
        let showHt = 425 || $(area).height(); //显示高度
        let actualHt = $(altitude).height();  // 实际总高度
        // 内容小于显示区域  不需要滚动条
        if (showHt < actualHt) {
            let scrollHt = showHt / actualHt * showHt // 滚动条高度 
            let scrollHtml = '<div class="scroll-sole"><div class="scroll-bar" style="height:'+scrollHt+'"></div></div>'
            $(container).prepend(scrollHtml);
            $('.scroll-bar').height(scrollHt)
            let clickY = '';
            let moveY = '';
            let barTop = 0;
            let moveCheck = Boolean;
            let moveOut = false;
            let scrollIndex = 0;
            $(area).mousedown(function (e) {
                moveCheck = true;
                clickY = e.pageY - $('.scroll-bar').position().top;
                $(this).mouseover(function (e) {
                    moveOut = false;
                })
                $(this).mousemove(function (e) {
                    if (moveCheck) {
                        moveY = e.pageY;
                        barTop = (moveY - clickY) >= showHt - scrollHt ? showHt - scrollHt : (moveY - clickY)
                        barTop = barTop <= 0 ? 0 : barTop;
                        // console.log('window:'+e.pageY+'clickY:'+clickY)
                        $('.scroll-bar').css({ top: barTop + 'px' })
                        $(this).scrollTop(barTop * (actualHt / showHt))
                        // console.log(barTop * (actualHt / showHt))
                    }
                })
                $(this).mouseup(function (e) {
                    if (moveCheck) {
                        moveCheck = false;
                        moveOut = true;
                        clickY = 0;
                    }
                })
                $(this).mouseout(function (e) {
                    if (!moveCheck && moveOut) {
                        moveCheck = false;
                        clickY = 0;
                    }
                })
            })
            $(area).on("mousewheel DOMMouseScroll", function (e) {
                let delta = (e.originalEvent.wheelDelta && (e.originalEvent.wheelDelta > 0 ? 1 : -1)) ||  // chrome & ie
                (e.originalEvent.detail && (e.originalEvent.detail > 0 ? -1 : 1));  
                e.preventDefault()
                // firefox
                if (delta > 0) {
                    // 向上滚
                    scrollIndex = scrollIndex + 10 >= showHt - scrollHt ? showHt - scrollHt : scrollIndex + 10;
                    $('.scroll-bar').css({ top: scrollIndex + 'px' })
                    $(this).scrollTop(scrollIndex * (actualHt / showHt))

                } else if (delta < 0) {
                    // 向下滚
                    scrollIndex = scrollIndex - 10 <= 0 ? 0 : scrollIndex - 10;
                    $('.scroll-bar').css({ top: scrollIndex + 'px' })
                    $(this).scrollTop(scrollIndex * (actualHt / showHt))
                }
            });
        }
        else{
            $(altitude).addClass('before-line');
        }

    }
    function formatDateTime(inputTime) {  
        let date = new Date(inputTime);
        let y = date.getFullYear();  
        let m = date.getMonth() + 1;  
        m = m < 10 ? ('0' + m) : m;  
        let d = date.getDate();  
        d = d < 10 ? ('0' + d) : d;  
        let h = date.getHours();
        h = h < 10 ? ('0' + h) : h;
        let minute = date.getMinutes();
        let second = date.getSeconds();
        minute = minute < 10 ? ('0' + minute) : minute;  
        second = second < 10 ? ('0' + second) : second; 
        return {
        'year':y,
        'month':m,
        'day':d,
        'hour':h,
        'minute':minute,
        'second':second
        }  
    };
    function GetUrlParam(paraName) {
        var url = document.location.toString();
        var arrObj = url.split("?");

        if (arrObj.length > 1) {
            var arrPara = arrObj[1].split("&");
            var arr;

            for (var i = 0; i < arrPara.length; i++) {
                arr = arrPara[i].split("=");

                if (arr != null && arr[0] == paraName) {
                    return arr[1];
                }
            }
            return "";
        }
        else {
            return "";
        }
    };
    window.uilts = {
        createScrollDom: createScrollDom,
        isFooterPosition: isFooterPosition,
        formatDateTime :formatDateTime,
        // URL:"http://10.10.1.45:9090/", // 郭甫接口
        URL:"http://101.37.23.169:9098/", //测试
        getUrlParam: GetUrlParam 
    }
})(window)

// 静止选中文字 
document.body.onselectstart = document.body.ondrag = function(){
    return false;
}

